<template>
  <a-modal
    class="noborder"
    :title="title"
    :width="520"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      
      <a-form :form="form">
      <a-form-item label="经销商id" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <span>经销商id为：{{record.user_id}}</span>
      </a-form-item>
        
        <a-form-item label="邀请人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            placeholder="请选择邀请人"
            v-decorator="['dealer_id']"
          >
            <a-select-option :value="0">无邀请人</a-select-option>
            <a-select-option
              v-for="(item, index) in dealerList"
              :key="index"
              :value="item.user_id"
            >{{item.user_id}}-{{ item.real_name }}</a-select-option>
          </a-select>
        </a-form-item>
        
       
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import * as Api from '@/api/user'
import { axios } from '@/utils/request'
export default {
  components: {
  },
  props: {
    // 邀请人uid和姓名
    dealerList:{
        type: Array,
        required: true
    },
  },
  data () {
    return {
      // 对话框标题
      title: '转移经销商',
      // 标签布局属性
      labelCol: { span: 7 },
      // 输入框布局属性
      wrapperCol: { span: 13 },
      // modal(对话框)是否可见
      visible: false,
      // modal(对话框)确定按钮 loading
      confirmLoading: false,
      // 当前表单元素
      form: this.$form.createForm(this),
      // 当前记录
      record: {}
    }
  },
  methods: {

    // 显示对话框
    handle (record) {
      // 显示窗口
      this.visible = true
      // 当前记录
      this.record = record
      // 设置默认值
      this.setFieldsValue()
    },

    /**
     * 设置默认值
     */
    setFieldsValue () {
      const { record, form: { setFieldsValue } } = this
      this.$nextTick(() => {
        setFieldsValue(pick(record, ['grade_id']))
      })
    },

    /**
     * 确认按钮
     */
    handleSubmit (e) {
      e.preventDefault()
      // 表单验证
      const { form: { validateFields } } = this
      validateFields((errors, values) => {
        // 提交到后端api
        !errors && this.onFormSubmit(values)
      })
    },

    /**
     * 关闭对话框事件
     */
    handleCancel () {
      this.visible = false
      this.form.resetFields()
    },

    /**
    * 提交到后端api
    */
    onFormSubmit (values) {
      // this.confirmLoading = true
      
      return Api.deletebd({ userId: this.record.user_id,buser_id:values.dealer_id })
        .then((result) => {
          
          // // 关闭对话框事件
          this.handleCancel()
          // // 通知父端组件提交完成了
          this.$emit('handleSubmit', values)
        })
        .finally(() => {
          // this.confirmLoading = false
        })
      
      
      return;
      
      
      axios({
          url: 'https://ceshi.chenguangjinpu.cn/index.php?s=/api/index/zhuces', // 你的API接口地址
          method: 'POST',
          data: {
              form: values, // 你要发送的POST数据
          }
      }).then((result) => {
        if(result.message!='分销商申请已提交')
        {
        	if(result.message=='手机号已存在')
        	{
        		
        		this.$message.error(result.message, 1.5)
        		
        	}else{
            
            this.$message.error(result.message, 1.5)
          }
          return;
        }else{
          
          this.$message.success(result.message, 1.5)
        }
        
          // // 关闭对话框事件
          this.handleCancel()
          // // 通知父端组件提交完成了
          this.$emit('handleSubmit', values)
        })
        .finally(() => {
          this.confirmLoading = false
        })
      
     
    }

  }
}
</script>
<style lang="less">
.ant-form-item {
  margin-bottom: 15px;
}
</style>
